import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common';
import { LinkService } from './link.service'
import { CreateLinkDto } from './dto/create-link.dto'
import { UpdateLinkDto } from './dto/update-link.dto'
import { AuthGuard } from '@nestjs/passport'

@Controller('link')
@UseGuards(AuthGuard('jwt'))
export class LinkController {
    constructor(private readonly linkService: LinkService) { }

    @Post()
    create(@Body() createLinkDto: CreateLinkDto) {
        return this.linkService.create(createLinkDto);
    }

    @Get()
    findAll(@Query() urlQuery: { status?: string, title: string, pageIndex: string, pageSize: string }) {
        const query = {
            status: urlQuery.status ? +urlQuery.status : undefined,
            title: urlQuery.title,
            pageIndex: +urlQuery.pageIndex,
            pageSize: +urlQuery.pageSize
        }
        return this.linkService.findAll(query);
    }

    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.linkService.findOne(+id);
    }

    @Patch(':id')
    update(@Param('id') id: string, @Body() updateLinkDto: UpdateLinkDto) {
        return this.linkService.update(+id, updateLinkDto);
    }

    @Delete(':id')
    remove(@Param('id') id: string) {
        return this.linkService.remove(+id);
    }
}
